const path = require('path')
const webpack = require('webpack')
const htmlWebpackPlugin = require('html-webpack-plugin')
const uglifyJsPlugin = require('uglifyjs-webpack-plugin')
module.exports = {
  // 入口，可以是字符串/数组/对象
  entry: './src/main.js',
  // 出口，通常是一个对象，里面至少包含path和filename
  output: {
    path: path.resolve(__dirname, 'dist'), // path通常是一个绝对路径,
    filename: 'bundle.js',
    // publicPath: 'dist/' // 给生成的静态资源路径添加前缀，运行时，html默认在其所在路径引用打包好的静态资源
  },
  module: {
    rules: [{
        test: /\.css$/,
        use: ['style-loader', 'css-loader']
      },
      {
        test: /\.less$/,
        use: [{
          loader: "style-loader" // creates style nodes from JS strings
        }, {
          loader: "css-loader" // translates CSS into CommonJS
        }, {
          loader: "less-loader" // compiles Less to CSS
        }]
      },
      {
        test: /\.(png|jpg|gif)$/,
        use: [{
          loader: 'url-loader',
          options: {
            limit: 8192, //当图片大小小于limit时候，对图片进行base64编码
            name: 'imgs/[name].[hash:16].[ext]'
          }
        }]
      },
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['es2015']
          }
        }
      },
      {
        test: /\.vue$/,
        use: ['vue-loader']
      }
    ]
  },
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js' // 使用vue的runtime-complier
    }
  },
  plugins: [
    new webpack.BannerPlugin('最终版权归崔帆所有'),
    new uglifyJsPlugin(),
    new htmlWebpackPlugin({
      template: 'index.html'
    }),
  ],
  devServer: {
    contentBase: './dist',
    inline: true
  }
}